package org.example.server.messagehandler.heartbeat;

import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.example.common.codec.Invocation;
import org.example.common.dispacher.MessageHandler;
import org.example.server.message.heartbeat.HeartbeatRequest;
import org.example.server.message.heartbeat.HeartbeatResponse;
import org.springframework.stereotype.Component;

/**
 * @title
 * @time 2025/6/16 17:33
 */
@Component
@Slf4j
public class HeartbeatRequestHandler implements MessageHandler<HeartbeatRequest> {
    @Override
    public void execute(Channel ch, HeartbeatRequest message) {
        log.info("[execute][收到连接:{} 的心跳请求]",ch.id());
        // 响应心跳
        HeartbeatResponse response = new HeartbeatResponse();
        ch.writeAndFlush(new Invocation(HeartbeatResponse.TYPE, response));
    }

    @Override
    public String getType() {
        return HeartbeatRequest.TYPE;
    }
}
